/*******************************************************************************
 * Package: com.song.boot.springstudy.webflux
 * Type:    Main01
 * Date:    2025/3/28 10:27
 *
 * Copyright (c) 2025 LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.song.boot.springstudy.webflux;


import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

/**
 * 功能描述：创建流
 *
 * @author Songxianyang
 * @date 2025/3/28 10:27
 */
public class Main01 {
    public static void main(String[] args) {
        Flux.just(1, 2, 36, 4, 25, 6, 7)
                .subscribe(System.out::print);

        // Mono.error(new Exception("error")).subscribe();

        Flux.create(s->{

            s.next("Event1");
            s.next("Event2");
            s.complete();
        }).subscribe(System.out::print);


        Flux.generate(
                ()->0,
                (s,v)-> {
                    v.next(s);
                    if (s == 5) {
                        v.complete();
                    }
                    return s + 1;
                }


        ).subscribe(System.out::print);

        Flux.fromIterable(Arrays.asList("1", "88", "77")).subscribe(System.out::println);
        Integer[] ssj ={1,44,99,77};
        Flux.fromArray(ssj).subscribe(System.out::println);


        Mono.fromFuture(CompletableFuture.supplyAsync(() -> "Result")).subscribe(System.out::println); // Future
        Flux.fromStream(Stream.of("a", "b")).subscribe(System.out::println);            // Stream


    }
}
